//
//  StarView.m
//  GlobalAuto
//
//  Created by 忧伤可乐 on 16/8/15.
//  Copyright © 2016年 jmhqmc. All rights reserved.
//

#import "StarView.h"
@implementation StarView
- (void)creatImage
{
    backgroundImageView=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"StarsBackground"]];
    backgroundImageView.frame=CGRectMake(0, 0, 96.5, 13);
    
    backgroundImageView.contentMode=UIViewContentModeLeft;
    foregroundImageView=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"StarsForeground"]];
    foregroundImageView.frame=CGRectMake(0, 0, 96.5, 13);
    //设置内容的对齐方式
    foregroundImageView.contentMode=UIViewContentModeLeft;
    //如果子视图超出父视图大小时被裁剪掉
    foregroundImageView.clipsToBounds=YES;
    [self addSubview:backgroundImageView];
    [self addSubview:foregroundImageView];
    self.backgroundColor=[UIColor clearColor];
}
- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        [self creatImage];
    }
    return self;
}

- (void)setStar:(CGFloat)star
{
    CGFloat starCount = 0 ;
    if ((star -(int) star)>0 && (star -(int) star <= 0.5)) {
        starCount =(int) star + 0.5 ;
    }
    else if ((star -(int) star)>0.5 && (star -(int) star)< 1) {
        starCount =(int) star + 1 ;
    }
    else if((star -(int) star)==0) {
        starCount =(int) star;
    }
    NSLog(@"%f",starCount);
    CGRect frame=backgroundImageView.frame;
    frame.size.width=frame.size.width*(starCount/5);
    foregroundImageView.frame=frame;
}
@end
